//
//  UploadImageRequest.m
//  fashionbuyer
//
//  Created by ale tan on 2018/1/30.
//  Copyright © 2018年 ale tan. All rights reserved.
//

#import "UploadImageRequest.h"

@implementation UploadImageRequest

- (id)init{
    self = [super init];
    if (self) {
        self.uploadUrl = @"user/v1/file/upload";
    }
    return self;
}

- (void)upLoadImage:(UIImage *)image Callback:(RequestResult)callback{
    self.requestCallBack = callback;
    
//    NSData *resizeData = UIImageJPEGRepresentation(image, 0.1);
//    long long size = resizeData.length/1000;
    
    [ServiceManager uploadImage:image toURL:self.uploadUrl withName:@"file" params:self.parameters success:^(id responseObject , BOOL result) {
        if (result) {
            self.requestCallBack(responseObject[@"data"][@"path"],result);
        }
        else{
            [FFTipsView showTips:responseObject[@"toast"]];
        }
        
    } failure:^(id error) {
        [FFTipsView showTips:@"网络连接失败"];
        self.requestCallBack(nil,NO);
        
    }];
}

@end
